/***
 * * PROJECT
 * *    ATaG
 * * VERSION
 * *    $Revision: 1.2 $
 * * DATE
 * *    $Date: 2007/06/09 07:15:49 $
 * * LOG
 * *    $Log: ATaGChannelDeclaration.java,v $
 * *    Revision 1.2  2007/06/09 07:15:49  animesh
 * *    update after fixing all but sets and serialization.
 * *
 * *    Revision 1.4  2007/01/15 09:10:05  animesh
 * *    no message
 * *
 * *    Revision 1.3  2006/10/21 00:17:53  animesh
 * *    no message
 * *
 * *    Revision 1.2  2006/10/19 21:21:53  lmottola
 * *    Added CVS preamble.
 * *
 * *
 * *   ATaG (Abstract Task Graph) - Data-driven Macroprogramming for
 * *                                Sensor Networks
 * *
 * *   This program is free software; you can redistribute it and/or
 * *   modify it under the terms of the GNU General Public License
 * *   as published by the Free Software Foundation; either version 2
 * *   of the License, or (at your option) any later version.
 * *
 * *   This program is distributed in the hope that it will be useful,
 * *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * *   GNU General Public License for more details.
 * *
 * *   You should have received a copy of the GNU General Public License
 * *   along with this program; if not, you may find a copy at the FSF web
 * *   site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
 * *   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * *   Boston, MA  02111-1307, USA
 ***/

package atag.common;

/**
 * A Channel in an ATaG Program
 * @author Animesh
 */
public class ATaGChannelDeclaration {
    
    //Directions
    public static final int CHANNEL_TYPE_INPUT = 0x01;
    public static final int CHANNEL_TYPE_OUTPUT = 0x02;
    
    private String taskName;
    private String dataName;
    private String interest;
    private int direction;
    
    private boolean isLocal;
    
    /**
     * unique ID. To be set during sanitization of code [checking for dupes etc.]
     */
    private int ID;

    /**
     * task ID. To be set during sanitization of code [checking for dupes etc.]
     */
    private int taskID;

    /**
     * data ID. To be set during sanitization of code [checking for dupes etc. ]
     */
    private int dataID;
    
    
    
    /**
     * Creates a new instance of ATaGChannelDeclaration
     */
    public ATaGChannelDeclaration() {
    }
    
    public void setTaskName(String newTaskName){
        this.taskName = new String(newTaskName);
    }
    
    public String getTaskName(){
        return this.taskName;
    }

    public void setDataName(String newDataName){
        this.dataName = new String(newDataName);
    }
    
    public String getDataName(){
        return this.dataName;
    }
    public void setDirection(int newDirection){
        this.direction = newDirection;
    }
    
    public int getDirection(){
        return this.direction;
    }
    
    public int getID() {
        return this.ID;
    }
    
    public void setID(int newID) {
        this.ID = newID;
    }

    public int getTaskID() {
        return this.taskID;
    }
    
    public void setTaskID(int newTaskID) {
        this.taskID = newTaskID;
    }
    public int getDataID() {
        return this.dataID;
    }
    
    public void setDataID(int newDataID) {
        this.dataID = newDataID;
    }
    
    public String getTypeInString(){
        String retString = "";
        if (this.direction == ATaGChannelDeclaration.CHANNEL_TYPE_OUTPUT)
            return new String("OUTPUT");
        else
            return new String("INPUT");
           
    }

    
    public void setLocalFlag(boolean newLocalFlag){
        this.isLocal = newLocalFlag;
    }
    
    public boolean isLocal() {
        //check if the interest string has a local attribute
        //change this to a boolean local operater later
        return this.isLocal;
    }

    public void setInterest(String newInterest){
        this.interest = new String(newInterest);
    }
    
    public String getInterest(){
        // parse the interest string and pick out the part before the colon
        //return this.interest.split(":")[0];
        return StringHelper.splitString(this.interest, ':')[0];
    }
    
    public String getInterestParam(){
        // parse the interest string and pick out the part after the colon
        String retString = null;
        try{
            //retString = this.interest.split(":")[1];
            retString = StringHelper.splitString(this.interest, ':')[1];
        }catch (ArrayIndexOutOfBoundsException ex){
            System.out.println("This "+this.getTypeInString()+" channel ("
                    + this.taskName + " " + this.dataName +" has interest string" +
                    this.interest + " which does not have a colon!");
            ex.printStackTrace();
        }
        
        return retString;
    }
    
}
